﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DealKhuyenMaiV2.com.Models;
using PagedList;

namespace DealKhuyenMaiV2.com.Controllers
{
    [DealKhuyenMaiV2.com.Controllers.AccountController.AdminAuthorize]
    public class StatusProductController : BaseController
    {
        //
        // GET: /StatusProduct/

        public ViewResult Index()
        {
            var statusproducts = DbConText.StatusProducts;
            int pageSize = 10;
            ViewBag.Methol = "Index";
            return View(statusproducts.ToList().ToPagedList(1, pageSize));
        }
        [HttpPost]
        public PartialViewResult Index(int? page)
        {
            var statusproducts = DbConText.StatusProducts;
            int pageSize = 10;
            int pageNumber = (page ?? 1);
            ViewBag.Methol = "Index";
            return PartialView("_ListStatusProduct", statusproducts.ToList().ToPagedList(pageNumber, pageSize));
        }
        //
        // GET: /StatusProduct/Details/5

        public ViewResult Details(short id)
        {
            StatusProduct statusproduct = DbConText.StatusProducts.Single(s => s.IDStatus == id);
            return View(statusproduct);
        }

        //
        // GET: /StatusProduct/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /StatusProduct/Create

        [HttpPost]
        public ActionResult Create(StatusProduct statusproduct)
        {
            if (ModelState.IsValid)
            {
                DbConText.StatusProducts.AddObject(statusproduct);
                DbConText.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(statusproduct);
        }

        //
        // GET: /StatusProduct/Edit/5

        public ActionResult Edit(short id)
        {
            StatusProduct statusproduct = DbConText.StatusProducts.Single(s => s.IDStatus == id);
            return View(statusproduct);
        }

        //
        // POST: /StatusProduct/Edit/5

        [HttpPost]
        public ActionResult Edit(short id, StatusProduct statusproduct)
        {
            StatusProduct _statusproduct = DbConText.StatusProducts.Single(s => s.IDStatus == id);
            {
                _statusproduct.NameStatus = statusproduct.NameStatus;
                _statusproduct.Description = statusproduct.Description;
            }
            if (ModelState.IsValid)
            {
                DbConText.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(statusproduct);
        }

        //
        // GET: /StatusProduct/Delete/5

        //public ActionResult Delete(short id)
        //{
        //    StatusProduct statusproduct = DbConText.StatusProducts.Single(s => s.IDStatus == id);
        //    return View(statusproduct);
        //}

        //
        // POST: /StatusProduct/Delete/5

        //[HttpPost, ActionName("Delete")]
        //public ActionResult DeleteConfirmed(short id)
        //{
        //    StatusProduct statusproduct = DbConText.StatusProducts.Single(s => s.IDStatus == id);
        //    DbConText.StatusProducts.DeleteObject(statusproduct);
        //    DbConText.SaveChanges();
        //    return RedirectToAction("Index");
        //}

        [HttpPost, ActionName("Delete")]
        public PartialViewResult DeleteConfirmed(int? page, int id)
        {
            StatusProduct statusproduct = DbConText.StatusProducts.Single(s => s.IDStatus == id);
            DbConText.StatusProducts.DeleteObject(statusproduct);
            DbConText.SaveChanges();

            var statusproducts = DbConText.StatusProducts;
            int pageSize = 10;
            int pageNumber = (page ?? 1);
            ViewBag.Methol = "Index";
            return PartialView("_ListStatusProduct", statusproducts.ToList().ToPagedList(pageNumber, pageSize));
        }
    }
}